/*
 * LCTClient.java
 *
 * Created on October 18, 2007, 1:42 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.lct.eq2.rmi;

import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.util.HashMap;
import com.lct.eq2.data.*;

/**
 *
 * @author waitek
 */
public class LCTClient {
    LCTRemote lctRemote;
    
    /** Creates a new instance of LCTClient */
    public LCTClient() {
        try {
            //System.setSecurityManager(new RMISecurityManager());
            lctRemote = (LCTRemote)Naming.lookup("rmi://litecombattracker.ath.cx:1099/LCTRemoteServer");
            //lctRemote = (LCTRemote)Naming.lookup("rmi://localhost:1099/LCTRemoteServer");
        } catch (RemoteException ex) {
            //ex.printStackTrace();
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (NotBoundException ex) {
            //ex.printStackTrace();
        } catch (ClassCastException ex) {
            ex.printStackTrace();
        }
    }
    
    public String getVersion() throws RemoteException {
        String rval = null;
//        try {
            rval = lctRemote.getVersion();
//        } catch (NullPointerException ex) {
//            // nothing
//        }
        return rval;
    }
    
    public HashMap getTimers() throws RemoteException {
        HashMap rval = null;
        try {
            rval = lctRemote.getTimers();
        } catch (NullPointerException e) {
            // nothing
        }
        return rval;
    }
    
    public void addRespawnTimer(RespawnTimer timer) throws RemoteException  {
        java.net.InetAddress localhost = null;
        try {
            localhost = java.net.InetAddress.getLocalHost();
        } catch (UnknownHostException ex) {
            ex.printStackTrace();
        }
        String clientID = localhost.toString();
        lctRemote.addRespawnTimer(timer, clientID);
    }
    
}
